﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Disposition : System.Web.UI.UserControl
{

    
    //public static string connString = "user id=portaluser;data source=172.25.9.26;initial catalog=VoiceNet_Focus;password=sqluser";

    //public SqlConnection conn = new SqlConnection(connString);

    protected void Page_Load(object sender, EventArgs e)
    {

        Response.Expires = -1;

        if (!IsPostBack)
        {
            
            lbDispo.DataSource = ((DataAccess)Session["App"]).GetUsercodes();
            lbDispo.DataTextField = ((DataAccess)Session["App"]).GetUsercodes().Columns["textField"].ColumnName.ToString();
            lbDispo.DataValueField = ((DataAccess)Session["App"]).GetUsercodes().Columns["usercode"].ColumnName.ToString();
            lbDispo.DataBind();
            lbDispo.Items.Insert(0, new ListItem("", ""));
            //LoadUsercodes();
        }
    }

    protected void lbDispo_SelectedIndexChanged(object sender, EventArgs e)
    {
        ((DataAccess)Session["App"]).PutCallData("webusercode", lbDispo.SelectedValue);
        ((DataAccess)Session["App"]).CommitCallData();
       // Session["App"] = App;
        //       UpdateResult();

    }

    //private void LoadUsercodes()
    //{
    //    SqlDataAdapter ProductTypesDA = default(SqlDataAdapter);
    //    DataSet ProductTypesDS = default(DataSet);

    //    connString = "user id=portalUser;data source=" + Session["servername"] + ";initial catalog=" + Session["projectname"] + ";password=sqluser";
    //    conn.ConnectionString = connString;

    //    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
    //    string lccommand = null;

    //    lccommand = "exec f_GetUserCodesForAgent '" + Session["campaignname"].ToString() + "' ";

    //    ProductTypesDA = new SqlDataAdapter(lccommand, conn);
    //    ProductTypesDS = new DataSet();
    //    ProductTypesDA.Fill(ProductTypesDS, "AllTables");
    //    //ddlProductTypes.DataSource = ProductTypesDS;
    //    lbDispo.DataSource = ProductTypesDS.Tables[0];
    //    lbDispo.DataTextField = ProductTypesDS.Tables[0].Columns["textField"].ColumnName.ToString();
    //    lbDispo.DataValueField = ProductTypesDS.Tables[0].Columns["usercode"].ColumnName.ToString();
    //    lbDispo.DataBind();
    //    lbDispo.Items.Insert(0, new ListItem("", ""));
    //    //ddlProductTypes.SelectedIndex = 0;
    //}



    //public void UpdateResult()
    //{
    //    string lccommand = null;
    //    SqlCommand command = new SqlCommand();


    //    ////get product data from product table
    //    connString = "user id=portalUser;data source=" + Session["servername"] + ";initial catalog=" + Session["projectname"] + ";password=sqluser";
    //    conn.ConnectionString = connString;
    //    conn.Open();
    //    lccommand = "update result set webusercode = '" + lbDispo.SelectedValue + "' where enterpriselistid = " + Session["listid"] + " ";
    //    command.CommandType = CommandType.Text;
    //    command.CommandText = lccommand;
    //    command.Connection = conn;

    //    if (command.ExecuteNonQuery() == 1)
    //    {
    //        //it worked
    //    }
    //    else
    //    {
    //        //it didn't work
    //    }
    //    conn.Close();

   // }
   
}